package com.cxh.rmsq.utils.dialog

import android.content.Context
import android.graphics.Color
import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isVisible
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cxh.rmsq.R
import com.hjq.shape.view.ShapeEditText
import com.lxj.xpopup.core.AttachPopupView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.impl.PartShadowPopupView

class JoinTimeSelectPopup(
    context: Context,
    type: Int,
    title: String,
    arrayList: MutableList<String>,
    click: onClick
) :
    PartShadowPopupView(context) {

    private val adapter3 by lazy { Adapter3() }

    interface onClick {
        fun click(s: Int, s1: String, s2: String, s3: String, s4: String)
    }

    var func: onClick

    var arrayList = mutableListOf<String>()
    var type = 0
    var title = ""

    init {
        this.func = click
        this.type = type
        this.title = title
        this.arrayList = arrayList
    }

    override fun getImplLayoutId(): Int {
        return R.layout.join_sel_popup
    }

    override fun onCreate() {
        super.onCreate()
        var recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.adapter = adapter3
        adapter3.setNewInstance(arrayList)

    }

    inner class Adapter3() :
        BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_time_sel/*, list*/),
        LoadMoreModule {
        var pos3 = -1
        override fun convert(holder: BaseViewHolder, item: String) {
            holder.run {
                var sort_name = holder.getView<TextView>(R.id.tv_time)
                sort_name.text = item

                holder.itemView.setOnClickListener {
                    pos3 = holder.layoutPosition
                    func.click(
                        pos3,
                        item,
                        "",
                        "",
                        ""
                    )
                    dismiss()
                }
                if (title == item) {
                    sort_name.setTextColor(Color.parseColor("#FFDF83"))
                } else {
                    sort_name.setTextColor(Color.parseColor("#D7CBA7"))
                }
            }
        }
    }

}